package cn.stylefeng.guns.modular.hx.basic.service.impl;

import java.io.Serializable;
import java.util.List;

import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import cn.stylefeng.guns.base.pojo.node.ZTreeNode;
import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.hx.basic.entity.HxBasicGoodsCode;
import cn.stylefeng.guns.modular.hx.basic.mapper.HxBasicGoodsCodeMapper;
import cn.stylefeng.guns.modular.hx.basic.model.params.HxBasicGoodsCodeParam;
import cn.stylefeng.guns.modular.hx.basic.model.result.HxBasicGoodsCodeResult;
import  cn.stylefeng.guns.modular.hx.basic.service.HxBasicGoodsCodeService;
import cn.stylefeng.roses.core.util.ToolUtil;

/**
 * <p>
 * 商品分类 服务实现类
 * </p>
 *
 * @author zhucx
 * @since 2024-01-10
 */
@Service
public class HxBasicGoodsCodeServiceImpl extends ServiceImpl<HxBasicGoodsCodeMapper, HxBasicGoodsCode> implements HxBasicGoodsCodeService {

    @Override
    public void add(HxBasicGoodsCodeParam param){
        HxBasicGoodsCode entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(HxBasicGoodsCodeParam param){
        this.removeById(getKey(param));
    }

    @Override
    public void update(HxBasicGoodsCodeParam param){
        HxBasicGoodsCode oldEntity = getOldEntity(param);
        HxBasicGoodsCode newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public HxBasicGoodsCodeResult findBySpec(HxBasicGoodsCodeParam param){
        return this.baseMapper.findBySpec(param);
    }

    @Override
    public List<HxBasicGoodsCodeResult> findListBySpec(HxBasicGoodsCodeParam param){
        return this.baseMapper.findListBySpec(param);
    }

    @Override
    public LayuiPageInfo findPageBySpec(HxBasicGoodsCodeParam param,String condition,Long operateId){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param,condition, operateId);
        return LayuiPageFactory.createPageInfo(page);
    }

    private Serializable getKey(HxBasicGoodsCodeParam param){
        return param.getId();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private HxBasicGoodsCode getOldEntity(HxBasicGoodsCodeParam param) {
        return this.getById(getKey(param));
    }

    private HxBasicGoodsCode getEntity(HxBasicGoodsCodeParam param) {
        HxBasicGoodsCode entity = new HxBasicGoodsCode();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }

	@Override
	public List<HxBasicGoodsCodeResult> likePids(Integer id) {
		return this.baseMapper.likePids(id);
	}

	@Override
	public List<ZTreeNode> tree(HxBasicGoodsCodeParam hxBasicGoodsCodeParam) {
		return this.baseMapper.tree(hxBasicGoodsCodeParam);
	}

}
